package com.wjh.anyview.auth.handler;

import com.wjh.anyview.auth.constant.SecurityConstant;
import com.wjh.anyview.entity.dto.ResultUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 验证不通过，返回 401
 *
 * @author wjh
 */
@Component
public class CustomHttp401AuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        ResultUtil.printCode(response, SecurityConstant.ACCESS_DENY, 401);
    }
}
